import { useUserStore } from "../store/user.js";

export const permsArr = [
  {
    name: "首页",
    permsName: "HOME",
    permsValue: "home",
    children: [
      {
        name: "统计分析",
        permsName: "HOME_HOMECENTER",
        permsValue: "home:homeCenter",
        children: [
          {
            name: "统计分析",
            permsName: "HOME_HOMECENTER_LIST",
            permsValue: "home:homeCenter:list",
          },
        ],
      },
      {
        name: "签章主页",
        permsName: "HOME_HOMESIGN",
        permsValue: "home:homeSign",
        children: [
          {
            name: "签署文件",
            permsName: "HOME_HOMESIGN_SIGN",
            permsValue: "home:homeSign:sign",
          },
          {
            name: "印章申领",
            permsName: "HOME_HOMESIGN_APPLYSEAL",
            permsValue: "home:homeSign:applySeal",
          },
          {
            name: "全网验证",
            permsName: "HOME_HOMESIGN_CHECKFILE",
            permsValue: "home:homeSign:checkFile",
          },
          {
            name: "公安验证",
            permsName: "HOME_HOMESIGN_CHECKFILE_GA",
            permsValue: "home:homeSign:checkFileGa",
          },
        ],
      },
    ],
  },
  {
    name: "合同管理",
    permsName: "CONTRACT",
    permsValue: "contract",
    children: [
      {
        name: "合同模版",
        permsName: "CONTRACT_CONTRACTTEMP",
        permsValue: "contract:contractTemp",
        children: [
          {
            name: "合同模版预览",
            permsName: "CONTRACT_CONTRACTTEMP_VIEW",
            permsValue: "contract:contractTemp:view",
          },
          {
            name: "合同模版下载",
            permsName: "CONTRACT_CONTRACTTEMP_DOWN",
            permsValue: "contract:contractTemp:down",
          },
        ],
      },
      {
        name: "我的合同",
        permsName: "CONTRACT_CONTRACTSELF",
        permsValue: "contract:contractSelf",
        children: [
          {
            name: "合同预览",
            permsName: "CONTRACT_CONTRACTSELF_VIEW",
            permsValue: "contract:contractSelf:view",
          },
          {
            name: "合同下载",
            permsName: "CONTRACT_CONTRACTSELF_DOWN",
            permsValue: "contract:contractSelf:down",
          },
          {
            name: "转入企业库",
            permsName: "CONTRACT_CONTRACTSELF_TOUNIT",
            permsValue: "contract:contractSelf:toUnit",
          },
        ],
      },
    ],
  },
  {
    name: "印章管理",
    permsName: "SEAL",
    permsValue: "seal",
    children: [
      {
        name: "印章列表",
        permsName: "SEAL_SEALLIST",
        permsValue: "seal:sealList",
        children: [
          {
            name: "印章列表",
            permsName: "SEAL_SEALLIST_LIST",
            permsValue: "seal:sealList:list",
          },
          {
            name: "印章注销",
            permsName: "SEAL_SEALLIST_DELETE",
            permsValue: "seal:sealList:delete",
          },
          // {
          //   name: "印章备案查看",
          //   permsName: "SEAL_SEALLIST_DOWN",
          //   permsValue: "seal:sealList:down",
          // },
          // {
          //   name: "印章授权",
          //   permsName: "SEAL_SEALLIST_AUTH",
          //   permsValue: "seal:sealList:auth",
          // },
          {
            name: "印章改密",
            permsName: "SEAL_SEALLIST_EDIT",
            permsValue: "seal:sealList:edit",
          },
        ],
      },
      {
        name: "印章签章记录",
        permsName: "SEAL_SIGNRECORD",
        permsValue: "seal:signRecord",
        children: [
          {
            name: "印章签章记录",
            permsName: "SEAL_SIGNRECORD_LIST",
            permsValue: "seal:signRecord:list",
          },
          {
            name: "印章签章记录刷新",
            permsName: "SEAL_SIGNRECORD_REFRESH",
            permsValue: "seal:signRecord:refresh",
          },
          {
            name: "印章签章记录下载",
            permsName: "SEAL_SIGNRECORD_DOWN",
            permsValue: "seal:signRecord:down",
          },
          {
            name: "印章签章记录删除",
            permsName: "SEAL_SIGNRECORD_DELETE",
            permsValue: "seal:signRecord:delete",
          },
        ],
      },
      {
        name: "授权记录",
        permsName: "SEAL_AUTHRECORD",
        permsValue: "seal:authRecord",
        children: [
          {
            name: "授权记录",
            permsName: "SEAL_AUTHRECORD_LIST",
            permsValue: "seal:authRecord:list",
          },
          {
            name: "授权记录暂停",
            permsName: "SEAL_AUTHRECORD_PAUSE",
            permsValue: "seal:authRecord:pause",
          },
          {
            name: "授权记录启用",
            permsName: "SEAL_AUTHRECORD_ENABLE",
            permsValue: "seal:authRecord:enable",
          },
        ],
      },
      {
        name: "申请记录",
        permsName: "SEAL_APPLYRECORD",
        permsValue: "seal:applyRecord",
        children: [
          {
            name: "申请记录",
            permsName: "SEAL_APPLYRECORD_LIST",
            permsValue: "seal:applyRecord:list",
          },
          {
            name: "申请记录通过",
            permsName: "SEAL_APPLYRECORD_APPROVED",
            permsValue: "seal:applyRecord:approved",
          },
          {
            name: "申请记录驳回",
            permsName: "SEAL_APPLYRECORD_REJECT",
            permsValue: "seal:applyRecord:rejecte",
          },
          {
            name: "申请记录申请用章",
            permsName: "SEAL_APPLYRECORD_USESEAL",
            permsValue: "seal:applyRecord:useSeal",
          },
          {
            name: "申请记录详情",
            permsName: "SEAL_APPLYRECORD_DETAIL",
            permsValue: "seal:applyRecord:detail",
          },
        ],
      },
      {
        name: "用章记录",
        permsName: "SEAL_USERECORD",
        permsValue: "seal:useRecord",
        children: [
          {
            name: "用章记录",
            permsName: "SEAL_USERECORD_LIST",
            permsValue: "seal:useRecord:list",
          },
        ],
      },
    ],
  },
  {
    name: "系统管理",
    permsName: "SYS",
    permsValue: "sys",
    children: [
      {
        name: "部门列表",
        permsName: "SYS_DEPART",
        permsValue: "sys:depart",
        children: [
          {
            name: "部门列表",
            permsName: "SYS_DEPART_LIST",
            permsValue: "sys:depart:list",
          },
          {
            name: "新增子公司",
            permsName: "SYS_DEPART_UNITADD",
            permsValue: "sys:depart:unitAdd",
          },
          {
            name: "新增部门",
            permsName: "SYS_DEPART_ADD",
            permsValue: "sys:depart:add",
          },
          {
            name: "删除部门",
            permsName: "SYS_DEPART_DELETE",
            permsValue: "sys:depart:delete",
          },
          {
            name: "编辑部门",
            permsName: "SYS_DEPART_EDIT",
            permsValue: "sys:depart:edit",
          },
        ],
      },
      {
        name: "角色列表",
        permsName: "SYS_ROLE",
        permsValue: "sys:role",
        children: [
          {
            name: "角色列表",
            permsName: "SYS_ROLE_LIST",
            permsValue: "sys:role:list",
          },
          {
            name: "角色新增",
            permsName: "SYS_ROLE_ADD",
            permsValue: "sys:role:add",
          },
          {
            name: "角色删除",
            permsName: "SYS_ROLE_DELETE",
            permsValue: "sys:role:delete",
          },
          {
            name: "角色编辑",
            permsName: "SYS_ROLE_EDIT",
            permsValue: "sys:role:edit",
          },
        ],
      },
      {
        name: "用户列表",
        permsName: "SYS_USER",
        permsValue: "sys:user",
        children: [
          {
            name: "用户列表",
            permsName: "SYS_USER_LIST",
            permsValue: "sys:user:list",
          },
          {
            name: "用户新增",
            permsName: "SYS_USER_ADD",
            permsValue: "sys:user:add",
          },
          {
            name: "用户删除",
            permsName: "SYS_USER_DELETE",
            permsValue: "sys:user:delete",
          },
          {
            name: "用户编辑",
            permsName: "SYS_USER_EDIT",
            permsValue: "sys:user:edit",
          },
          {
            name: "状态更改",
            permsName: "SYS_USER_STATUS",
            permsValue: "sys:user:status",
          },
        ],
      },
    ],
  },
];

export function perms() {
  let permsObj = {};
  permsArr.forEach((item) => {
    permsObj[item.permsName] = item.permsValue;
    item.children.forEach((childItem) => {
      permsObj[childItem.permsName] = childItem.permsValue;
      childItem.children.forEach((item_) => {
        permsObj[item_.permsName] = item_.permsValue;
      });
    });
  });
  return permsObj;
}

export function regPerms(name) {
  return useUserStore().perms.includes(perms()[name]);
}
